/**
 * MeetRoomAction.java
 */
package com.prs.crm.action.meeting;

import java.util.Collection;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.hr.Dept;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.meeting.MeetRoom;
import com.prs.crm.domain.person.Department;
import com.prs.crm.domain.person.DossierCultivate;
import com.prs.crm.service.hr.DeptService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.meeting.MeetRoomService;
import com.prs.crm.service.person.DepartmentService;

/**
 * @author ZhuDongMei
 * @E-mail:1223984339@qq.com
 * @qq:1223984339
 * @version 创建时间：2011-3-16 上午11:12:28 简单说明
 */

public class MeetRoomAction extends BaseAction {
	private static final long serialVersionUID = 1L;
    private MeetRoom meetRoom;
    private MeetRoomService meetRoomService;
    private Integer[] meetRoomIds;
    private PaginationSupport pagination;
    private List<Person> person;
    private PersonService personService;
    private Collection<Dept> depts;
    private DeptService deptService;
    private Integer confirm;
	public Integer getConfirm() {
		return confirm;
	}
	public void setConfirm(Integer confirm) {
		this.confirm = confirm;
	}
	public DeptService getDeptService() {
		return deptService;
	}
	public void setDeptService(DeptService deptService) {
		this.deptService = deptService;
	}
	
	public Collection<Dept> getDepts() {
		return depts;
	}
	public void setDepts(Collection<Dept> depts) {
		this.depts = depts;
	}
	public List<Person> getPerson() {
		return person;
	}
	public void setPerson(List<Person> person) {
		this.person = person;
	}
	public PersonService getPersonService() {
		return personService;
	}
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}
	public MeetRoom getMeetRoom() {
		return meetRoom;
	}
	public void setMeetRoom(MeetRoom meetRoom) {
		this.meetRoom = meetRoom;
	}
	public MeetRoomService getMeetRoomService() {
		return meetRoomService;
	}
	public void setMeetRoomService(MeetRoomService meetRoomService) {
		this.meetRoomService = meetRoomService;
	}
	public Integer[] getMeetRoomIds() {
		return meetRoomIds;
	}
	public void setMeetRoomIds(Integer[] meetRoomIds) {
		this.meetRoomIds = meetRoomIds;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	@Action("listMeetRoom")
	public String listMeetRoom(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(MeetRoom.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getMeetRoomService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("selectMeetRoom")
	public String selectMeetRoom(){
		this.listMeetRoom();
		return SUCCESS;
	}
	@Action("editMeetRoom")
	public String editMeetRoom(){
		if(meetRoomIds!=null){
	        this.meetRoom = this.getMeetRoomService().get(meetRoomIds[0]);
		}
		depts = this.getDeptService().getAllDepts();
		return SUCCESS;
	}
	@Action(value="saveMeetRoom",results={
			@Result(name="success",type="redirect",location="listMeetRoom"),
			@Result(name="error",type="chain",location="editMeetRoom")
	})
	public String saveMeetRoom(){
		if (meetRoom.getName()==null || "".equals(meetRoom.getName().trim())) {
			this.addActionError("请输入会议室名称");
			return ERROR;
		}
		if(meetRoom!=null){
				this.getMeetRoomService().save(meetRoom);
		}
		String str=meetRoom.getPersonId();
		String str2[]=str.split(",");
		return SUCCESS;
	}
	@Action(value="removeMeetRoom",results={
			@Result(name="success",type="redirect",location="listMeetRoom"),
			@Result(name="error",type="chain",location="listMeetRoom")
	})
	public String removeMeetRoom(){
		if(meetRoomIds==null){
			this.addActionError("请选择要删除的会议室！");
			return ERROR;
		}
		this.getMeetRoomService().batchRemove(this.getMeetRoomIds());
		return SUCCESS;
	}
}
